home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Visual Basic 4 Database How-To
/
Visual Basic 4 Database - How-to (The Waite Group)(1995).iso
/
dde.fr_
/
dde.fr
Wrap
Text File
|
1995-07-05
|
7KB
|
234 lines
VERSION 4.00
Begin VB.Form Form1
BackColor = &H00C0C0C0&
Caption = "DDE Report Printer"
ClientHeight = 2310
ClientLeft = 1095
ClientTop = 1740
ClientWidth = 5955
Height = 2715
Left = 1035
LinkTopic = "Form1"
ScaleHeight = 2310
ScaleWidth = 5955
Top = 1395
Width = 6075
Begin VB.CommandButton cmdClose
Cancel = -1 'True
Caption = "&Close"
BeginProperty Font
name = "MS Sans Serif"
charset = 0
weight = 700
size = 8.25
underline = 0 'False
italic = 0 'False
strikethrough = 0 'False
EndProperty
Height = 555
Left = 3480
TabIndex = 2
Top = 900
Width = 1455
End
Begin VB.CommandButton cmdPrintReport
Caption = "&Print Report"
Default = -1 'True
BeginProperty Font
name = "MS Sans Serif"
charset = 0
weight = 700
size = 8.25
underline = 0 'False
italic = 0 'False
strikethrough = 0 'False
EndProperty
Height = 555
Left = 1140
TabIndex = 1
Top = 900
Width = 1455
End
Begin VB.Label lblMessage
Alignment = 2 'Center
BackColor = &H00C0C0C0&
BeginProperty Font
name = "MS Sans Serif"
charset = 0
weight = 700
size = 9.75
underline = 0 'False
italic = 0 'False
strikethrough = 0 'False
EndProperty
Height = 435
Left = 960
TabIndex = 3
Top = 240
Width = 4155
End
Begin VB.Label lblDDE
Height = 255
Left = 1860
TabIndex = 0
Top = 1680
Visible = 0 'False
Width = 2895
WordWrap = -1 'True
End
End
Attribute VB_Name = "Form1"
Attribute VB_Creatable = False
Attribute VB_Exposed = False
Option Explicit
Const dbName = "D:\VB4\REPORTER.MDB"
Private OpenedDatabase As Boolean
Private StartedAccess As Boolean
Private Sub Form_Load()
Dim dbName As String
' Set the error handler
On Error GoTo LoadError
' Get the database name.
dbName = DataPath() & "\CHAPTER.04\REPORTER.MDB" ' DataPath() is in READINI.BAS
' Show the form so that the user can see the messages diusplayed
' during the Load event.
Me.Show
Me.Refresh
' Set the link topic to Microsoft Access. If you have Access version 1.1,
' change MSACCESS to ACCESS.
lblDDE.LinkTopic = "MSACCESS|SYSTEM"
' Set error handling for the DDE initiate process, then try to establish
' the link. If the link attempt fails, an error is generated.
On Error GoTo StartAccess
lblDDE.LinkMode = 2
' Reestablish the original error handler
On Error GoTo LoadError
' Get a list of "Topics" - open databases - from Access
lblDDE.LinkItem = "Topics"
lblDDE.LinkRequest
If InStr(lblDDE, dbName) = 0 Then
' The REPORTER database is not open, so open it and set the
' flag that indicates that this application has opened it.
lblMessage.Caption = "Opening Database"
lblDDE.LinkExecute "[OpenDatabase " & dbName & "]"
OpenedDatabase = True
lblMessage.Caption = "Database Opened"
Else
lblMessage.Caption = "Database is Open"
End If
Exit Sub
StartAccess:
Dim dummy As Integer
Dim triedOnce As Boolean
Dim pathToAccess As String
' This error routine is called when the link attempt fails. The first
' time it is called, triedOnce will be false, so it will attempt to
' start Access.
If Not triedOnce Then
lblMessage.Caption = "Starting Microsoft Access"
Me.Refresh
' Get the path to the installation's copy of Microsoft Access.
pathToAccess = AccessPath()
If pathToAccess <> "" Then
' WIN.INI has a path to Access, so try to start Access running.
' Then set focus back to the current app.
dummy = Shell(pathToAccess)
Me.SetFocus
' Set the triedOnce variable to indicate that we've tried
' to start Access.
triedOnce = True
' Set the StartedAccess flag to indicate that this app started
' Access.
StartedAccess = True
lblMessage.Caption = "Access Started"
' Go back and try the link again.
Resume
Else
' No path to Access in WIN.INI (at least not where we've looked!)
MsgBox "Cannot find path to Microsoft Access", vbCritical
End If
Else
' We tried to start Access once, but the link still fails. Time
' to inform the user and give up.
MsgBox "Cannot start " & pathToAccess, vbCritical
End If
End
LoadError:
MsgBox Error$, vbCritical
End
End Sub
Private Sub cmdPrintReport_Click()
On Error GoTo PrintError
' Set the timeout value to a long enough value to let the report
' print. A long report would require a higher value.
lblDDE.LinkTimeout = 600 ' 60 seconds
lblMessage = "Printing Report"
Screen.MousePointer = 11
' Use DDE to execute the Publisher Labels Report macro in the
' REPORTER.MDB database.
lblDDE.LinkExecute "[Publisher Labels Report]"
lblMessage = "Report Printed"
Screen.MousePointer = 0
' Return the focus back to the current application.
Me.SetFocus
Exit Sub
PrintError:
Screen.MousePointer = 0
MsgBox Error$, vbExclamation
Exit Sub
End Sub
Private Sub Form_Unload(Cancel As Integer)
' Ignore any errors; they will occur if someone has already closed the
' database and/or Access, and that's okay.
On Error Resume Next
Screen.MousePointer = 11
If StartedAccess Then
' This app started access, so execute then Access Quit action,
' which closes Access.
lblDDE.LinkExecute "[Quit]"
ElseIf OpenedDatabase Then
' We didn't start Access, but we did open the database. So close it.
lblDDE.LinkExecute "[CloseDatabase]"
End If
Screen.MousePointer = 0
End Sub
Private Sub cmdClose_Click()
Unload Me
End Sub